package high.concurrent.controller;

import high.concurrent.dto.MsgDto;
import high.concurrent.service.TxMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author 黄保泽
 * 描述 :
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/api/v1/message")
public class TxMsgController{

    private static final Logger LOGGER = LoggerFactory.getLogger(TxMsgController.class);
    @Autowired(required = false)
    private TxMsgService txMsgService;


    /**
     * 创建消息数据，并且状态默认是未发送
     * @param txMsgDTOData
     */
    @PostMapping("/createMsgDataByMsgService")
    public MsgDto createMsgDataByMsgService(@RequestBody MsgDto txMsgDTOData) {

        MsgDto txMsgDTO = new MsgDto();

        txMsgDTO = txMsgService.createMsgDataByMsgService(txMsgDTOData);

        return txMsgDTO;

    }

    /**
     * 根据msgId更改消息数据状态为已发送
     * @param txMsgDTO
     */
    @PostMapping("/updateMsgDataByMsgService")
    public void updateMsgDataByMsgService(@RequestBody MsgDto txMsgDTO) {

        txMsgService.updateMsgDataByMsgService(txMsgDTO.getMsgId());

    }

    /**
     * 通知消息服务，删除对应订单的消息数据
     * @param txMsgDTO
     */
    @PostMapping("delMsgByOrderNo")
    public void delMsgByOrderNo(@RequestBody MsgDto txMsgDTO) {

        txMsgService.delMsgDataByOrderNo(txMsgDTO);

    }


}
